//
//  XQCourseVideoTableHeaderView.swift
//  XiaoQiQiaoSwift
//
//  Created by tech-lab on 2016/12/2.
//  Copyright © 2016年 校企桥. All rights reserved.
//

import UIKit

class XQCourseVideoTableHeaderView: UIView {
    var videoView = UIWebView()
    var line = UIView()
    var backButton = UIButton()
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        InitUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func InitUI(){
    
    
        self.backgroundColor = UIColor.groupTableViewBackground
        self.isUserInteractionEnabled = true
        
        videoView = UIWebView.init(frame: CGRect.zero)
        self.addSubview(videoView)
        
        backButton = UIButton.init(frame: CGRect.zero)
        backButton .setImage(UIImage.init(named: "back"), for: .normal)
        videoView.addSubview(backButton)
        
        
        videoView.snp.makeConstraints { (make) in
            make.left.equalTo(self.snp.left)
            make.top.equalTo(self.snp.top).offset(20)
            make.right.equalTo(self.snp.right)
            make.height.equalTo(220)
        }
        
        backButton.snp.makeConstraints { (make) in
            make.left.equalTo(videoView.snp.left).offset(10)
            make.centerY.equalTo(videoView.snp.centerY)
            make.width.equalTo(30)
            make.height.equalTo(30)
        }
        
        let zhangjieButton = UIButton.init(frame: CGRect.zero)
        zhangjieButton.setTitle("章节", for: .normal)
        zhangjieButton.setTitleColor(UIColor.black, for: .normal)
        zhangjieButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        zhangjieButton.backgroundColor = UIColor.white
        self.addSubview(zhangjieButton)
        
        let pinglunButton = UIButton.init(frame: CGRect.zero)
        pinglunButton.setTitle("评论", for: .normal)
        pinglunButton.setTitleColor(UIColor.black, for: .normal)
        pinglunButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        pinglunButton.backgroundColor = UIColor.white
        self.addSubview(pinglunButton)
        
        zhangjieButton.tag = 1
        pinglunButton.tag = 2
        zhangjieButton.addTarget(self, action: #selector(self.qiehuanAction), for: .touchUpInside)
        pinglunButton.addTarget(self, action: #selector(self.qiehuanAction), for: .touchUpInside)
        
        let line1 = UIView.init(frame: CGRect.zero)
        line1.backgroundColor = UIColor.gray
        self.addSubview(line1)
        
        line = UIView.init(frame: CGRect.zero)
        line.backgroundColor = UIColor.blue
        self.addSubview(line)
        
        zhangjieButton.snp.makeConstraints { (make) in
            make.height.equalTo(40)
            make.left.equalTo(self.snp.left)
            make.top.equalTo(videoView.snp.bottom).offset(5)
            make.right.equalTo(self.snp.centerX)
        }
        
        
        pinglunButton.snp.makeConstraints { (make) in
            make.height.equalTo(40)
            make.right.equalTo(self.snp.right)
            make.top.equalTo(videoView.snp.bottom).offset(5)
            make.left.equalTo(self.snp.centerX)
        }
        
        
        
        
        line1.snp.makeConstraints { (make) in
            make.width.equalTo(1)
            make.height.equalTo(40)
            make.left.equalTo(zhangjieButton.snp.right)
            make.centerY.equalTo(zhangjieButton.snp.centerY)
            
        }
        
        line.snp.makeConstraints { (make) in
            make.centerX.equalTo(zhangjieButton.snp.centerX)
            make.bottom.equalTo(zhangjieButton.snp.bottom)
            make.height.equalTo(2)
            make.width.equalTo(SCREEN_WIDTH/2-60)
        }
    }
    
    @objc private func qiehuanAction(sender:UIButton)  {
        print("-------")
        line.center.x = sender.center.x
        if sender.tag == 1 {
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "courseChapter"), object: nil)
        }else{
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "courseComment"), object: nil)

        }
        
        
    }

}
